]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
telepathyClient: Do a better job with old chat timestamps
authorOwen W. Taylor <otaylor@fishsoup.net>
Mon, 28 Mar 2011 20:37:53 +0000 (16:37 -0400)
committerOwen W. Taylor <otaylor@fishsoup.net>
Tue, 29 Mar 2011 03:05:55 +0000 (23:05 -0400)
If we have a date that's not within the last week, it's really
confusing to display it as "Sent at 9:23 on Tuesday". Steal
some strings from calendar.js for displaying older dates to
avoid a string-freeze break.

https://bugzilla.gnome.org/show_bug.cgi?id=645609

js/ui/telepathyClient.js

index 675181a260c4f6ef67ae573db693dc4c3c87e31c..cc653e7fdb1becc67b462d5cd1e284d8c29886f6 100644 (file)
@@ -11,6 +11,7 @@ const Tpl = imports.gi.TelepathyLogger;
 const Tp = imports.gi.TelepathyGLib;
 const Gettext = imports.gettext.domain('gnome-shell');
 const _ = Gettext.gettext;
+const C_ = Gettext.pgettext;
 
 const History = imports.misc.history;
 const Main = imports.ui.main;
@@ -465,15 +466,39 @@ Notification.prototype = {
         }
     },
 
+    _formatTimestamp: function(date) {
+        let now = new Date();
+
+        var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
+
+        // Show a week day and time if date is in the last week
+        if (daysAgo < 1 || (daysAgo < 7 && now.getDay() != date.getDay())) {
+            /* Translators: this is a time format string followed by a date.
+             If applicable, replace %X with a strftime format valid for your
+             locale, without seconds. */
+            // xgettext:no-c-format
+            format = _("Sent at %X on %A");
+
+        // FIXME: The next two are stolen from calendar.js with the comment to avoid
+        // a string-freeze break. They should be replaced with better strings
+        // with 'Sent at', appropriate context and appropriate translator comment.
+
+        } else if (date.getYear() == now.getYear()) {
+            /* Translators: Shown on calendar heading when selected day occurs on current year */
+            format = C_("calendar heading", "%A, %B %d");
+        } else {
+            /* Translators: Shown on calendar heading when selected day occurs on different year */
+            format = C_("calendar heading", "%A, %B %d, %Y");
+        }
+
+        return date.toLocaleFormat(format);
+    },
+
     appendTimestamp: function() {
         let lastMessageTime = this._history[0].time;
         let lastMessageDate = new Date(lastMessageTime * 1000);
 
-        /* Translators: this is a time format string followed by a date.
-           If applicable, replace %X with a strftime format valid for your
-           locale, without seconds. */
-        // xgettext:no-c-format
-        let timeLabel = this.addBody(lastMessageDate.toLocaleFormat(_("Sent at %X on %A")), false, { expand: true, x_fill: false, x_align: St.Align.END });
+        let timeLabel = this.addBody(this._formatTimestamp(lastMessageDate), false, { expand: true, x_fill: false, x_align: St.Align.END });
         timeLabel.add_style_class_name('chat-meta-message');
         this._history.unshift({ actor: timeLabel, time: lastMessageTime, realMessage: false });